{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 普通交叉验证"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "train_X.count:712,test_X.count:179,train_Y.count:712,test_Y.count:179\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"Titanic-dataset/train.csv\",encoding='utf8')\n",
    "df_X = df[['PassengerId','Pclass', 'Name', 'Sex', 'Age', 'SibSp','Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked']]\n",
    "df_Y = df[\"Survived\"]\n",
    "train_X,test_X,train_Y,test_Y = train_test_split(df_X.values,df_Y.values,test_size=0.2,random_state=1314)\n",
    "print(\"train_X.count:{},test_X.count:{},train_Y.count:{},test_Y.count:{}\".format(len(train_X),len(test_X),len(train_Y),len(test_Y)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### K折交叉验证"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "712 179\n",
      "713 178\n",
      "713 178\n",
      "713 178\n",
      "713 178\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import KFold\n",
    "kfold= KFold(n_splits=5,random_state =1314,shuffle=True)\n",
    "for train_index,test_index in kfold.split(df_X.values):\n",
    "    print(len(train_index),len(test_index))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
